import pandas as pd
data = pd.read_csv('metadata.csv')
data = data[data['type'] == 'impedance']
impedance_df = data.drop(['type', 'ambient_temperature', 'test_id', 'uid', 'Capacity', 'filename'], axis=1)
impedance_df.head()
| start_time | battery_id | Re | Rct | |
|---|---|---|---|---|
| 1 | [2010. 7. 21. 16. 53. ... | B0047 | 0.05605783343888099 | 0.20097016584458333 |
| 3 | [2010 7 21 20 31 5] | B0047 | 0.05319185850921101 | 0.16473399914864734 |
| 13 | [2010. 7. 22. 17. 3. ... | B0047 | 0.05963791501051059 | 0.21039872263834902 |
| 15 | [2010. 7. 22. 20. 40. 25.5] | B0047 | 0.05512505361624278 | 0.1754882075917004 |
| 17 | [2010. 7. 23. 11. 35. ... | B0047 | 0.058878485312444453 | 0.19095687096090014 |
impedance_df['start_time'].count()
1956
import pandas as pd
from datetime import datetime
data = pd.read_csv('metadata.csv')
data = data[data['type'] == 'impedance']
impedance_df = data.drop(['type', 'ambient_temperature', 'test_id', 'uid', 'Capacity', 'filename'], axis=1)
impedance_df['start_time'] = impedance_df['start_time'].astype(str)
impedance_df['start_time'] = impedance_df['start_time'].str.strip("[]").str.replace(",", "")
components = impedance_df['start_time'].str.split()
valid_start_times = []
for component in components:
if len(component) == 6:
year = int(float(component[0]))
month = int(float(component[1]))
day = int(float(component[2]))
hour = int(float(component[3]))
minute = int(float(component[4]))
second = int(float(component[5]))
valid_start_times.append(datetime(year, month, day, hour, minute, second))
else:
valid_start_times.append(pd.NaT)
impedance_df['start_time'] = valid_start_times
impedance_df = impedance_df.dropna(subset=['start_time'])
impedance_df = impedance_df.sort_values(by='start_time')
impedance_df.head()
| start_time | battery_id | Re | Rct | |
|---|---|---|---|---|
| 5160 | 2008-04-18 20:55:29 | B0005 | 0.04466870036616091 | 0.06945627304536996 |
| 5776 | 2008-04-18 20:55:29 | B0007 | 0.03816813609946085 | 0.06158094574229446 |
| 4544 | 2008-04-18 20:55:29 | B0006 | 0.06123359021000344 | 0.0785415394665875 |
| 4546 | 2008-04-18 22:39:16 | B0006 | 0.06561684946388616 | 0.0886832084583472 |
| 5162 | 2008-04-18 22:39:16 | B0005 | 0.04668700162486933 | 0.07627474098530587 |
impedance_df['start_time'].count()
1956
import plotly.graph_objects as go
fig = go.Figure()
for unique_battery in impedance_df['battery_id'].unique():
battery = impedance_df[impedance_df['battery_id'] == unique_battery]
fig.add_trace(go.Scatter(
x=battery['start_time'],
y=battery['Re'],
mode='lines+markers',
name=f'Resistance (Battery {unique_battery})',
line=dict(width=1, color='royalblue'),
marker=dict(size=4, color='darkblue')
))
fig.add_trace(go.Scatter(
x=battery['start_time'],
y=battery['Rct'],
mode='lines+markers',
name=f'Charge Transfer Resistance (Battery {unique_battery})',
line=dict(width=1, color='darkorange'),
marker=dict(size=4, color='red')
))
fig.update_layout(
title="Battery Impedance Trends",
xaxis_title="Timestamp",
yaxis_title="Resistance in Ohms",
xaxis=dict(showgrid=True, tickangle=90),
yaxis=dict(showgrid=True),
legend_title="Battery Types",
template="plotly_white",
plot_bgcolor="white"
)
fig.show()